function setupMenu() {
    $(".menu").button({
        icons : {
            primary : "ui-icon-gear",
            secondary : "ui-icon-triangle-1-s"
        }
    });
    $(".menuItem").menu();
    $(".menu ul").hide();
    $(".menu").mouseenter(function() {
        $(this).find("ul").fadeIn();
    });
    $(".menu").mouseleave(function() {
        $(this).find("ul").hide();
    });
}

function setupContent() {
    $("#tabs").tabs();
}

function message(text, type, layout) {
    noty({
        text : text,
        type : type,
        dismissQueue : true,
        layout : layout,
        theme : 'defaultTheme',
        modal : true,
        buttons : [ {
            addClass : 'btn btn-primary',
            text : '确定',
            onClick : function($noty) {
                $noty.close();
            }
        } ]
    });
}

function messageWithoutBtn(text, type, layout) {
    noty({
        text : text,
        type : type,
        dismissQueue : true,
        modal : false,
        timout : 2000,
        layout : layout,
        theme : 'defaultTheme'
    });
}

function confirm(text, layout, callback) {
    noty({
        text : text,
        type : 'alert',
        dismissQueue : true,
        modal : true,
        layout : layout,
        theme : 'defaultTheme',
        modal : true,
        buttons : [ {
            addClass : 'btn btn-primary',
            text : '确定',
            onClick : function($noty) {
                $noty.close();
                callback();
            }
        }, {
            addClass : 'btn btn-primary',
            text : '取消',
            onClick : function($noty) {
                $noty.close();
            }
        } ]
    });
}

function isDigit(s) {
    var patrn = /^\d+$/;
    if (patrn.exec(s))
        return true;
    return false;
}

function isAlpha(s) {
    var patrn = /^[0-9a-zA-Z]+$/;
    if (patrn.exec(s))
        return true;
    return false;
}

function isDate(value) {
    var reg = /^(\d{4})-(\d{2})-(\d{2})$/;
    var str = value;
    if (str == "")
        return true;
    if (!reg.test(str) && RegExp.$2 <= 12 && RegExp.$3 <= 31) {
        return false;
    }
    return true;
}

function dealError(data) {
    var result = eval("(" + data.responseText + ")");
    message(result.errorMsg, 'alert', 'center');
}

function getSexMatchCode(txt) {
    return getMatchCode(sexArray, txt);
}

function getEducationMatchCode(txt) {
    return getMatchCode(educationArray, txt);
}

function getEducationTypeMatchCode(txt) {
    return getMatchCode(educationTypeArray, txt);
}

function getCallAimMatchCode(txt) {
    return getMatchCode(callAimArray, txt);
}

function getMatchCode(array, txt) {
    var codeArray = new Array();
    for (var i = 0; i < array.length; i++) {
        var o = array[i];
        if (o.text.indexOf(txt) >= 0) {
            codeArray.push(o.code);
        }
    }
    return codeArray;
}
